<template>
  <div class="body">
    <div class="box">
      <h2>登录</h2>
      <div class="con">
        <el-input placeholder="请输入账号" clearable v-model="user.username"></el-input>
      </div>
      <div class="con">
        <el-input placeholder="请输入密码" clearable show-password v-model="user.password"></el-input>
      </div>
      <div class="con">
        <el-button type="primary" @click="login" class="btn">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { requserlogin } from "../../request/api";
import { successAlert } from "../../utils/alert";
import {mapActions} from "vuex"
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    ...mapActions({
          cuser:"useractions"
    }),
    login() {
      requserlogin(this.user).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          //  console.log(res);
          this.cuser(res.data.list)
          this.$router.push("/index");
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../less/index.less";
.body {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(90deg, @primary, @info);
  position: relative;
}
.box {
  width: 500px;
  height: 300px;
  background-color: #fff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 30px;
}
.box h2,
.box .con {
  text-align: center;
  margin: @margin 0;
}
.box .con .el-input {
  width: 450px;
  margin-bottom: @margin;
}
.el-button {
  width: 450px;
}
.btn{
  background-color: #2db7f5;
}
</style>